package com.canyou.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.canyou.utils.Oauth2Utils;
import org.apache.ibatis.reflection.MetaObject;

import java.time.LocalDateTime;

/**
 * 属性自动填充值
 *
 * @author cgz
 * @Date 2019/01/21
 **/
public class CysMetaObjectHandler implements MetaObjectHandler {

    private static String CREATE_BY = "createBy";
    private static String CREATE_TIME = "createTime";
    private static String MODIFY_BY = "modifyBy";
    private static String MODIFY_TIME = "modifyTime";

    @Override
    public void insertFill(MetaObject metaObject) {
        setFieldValByName(CREATE_TIME, LocalDateTime.now(), metaObject);
        setFieldValByName(CREATE_BY, Oauth2Utils.getUserName(), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        setFieldValByName(MODIFY_TIME, LocalDateTime.now(), metaObject);
        setFieldValByName(MODIFY_BY, Oauth2Utils.getUserName(), metaObject);
    }
}
